package com.dhms.vostok1.data.spot_patrol

import com.dhms.uikit.media.MediaType
import com.dhms.uikit.select_bottom_sheet.SelectItem
import com.squareup.moshi.Json
import io.realm.kotlin.ext.realmListOf
import io.realm.kotlin.types.RealmList
import io.realm.kotlin.types.RealmObject


enum class AttachmentType(var code: Int) {
    UNKNOWN(-1),

    //图片
    PHOTO(1),

    //视频
    VIDEO(2),

    //声音
    AUDIO(3);


    companion object {
        fun fromInt(type: Int) = AttachmentType.values()
            .associateBy(AttachmentType::code)[type] ?: UNKNOWN

        fun convertToMediaType(type: AttachmentType?): MediaType {
            return when (type) {
                AttachmentType.VIDEO -> MediaType.VIDEO
                AttachmentType.PHOTO -> MediaType.PHOTO
                AttachmentType.AUDIO -> MediaType.AUDIO
                else -> {
                    MediaType.PHOTO
                }
            }
        }
    }
}
//五官检查
class FiveSensesData : RealmObject {
    /*  检查项目 */
    @Json(name = "check_item")
    var checkItem: String? = null

    /*  抄表检查 */
    @Json(name = "check_standard")
    var checkStandard: String? = null

    /*  是否异常 */
    @Json(name = "is_abnormal")
    var isAbnormal: Boolean? = false

    /*  异常id */
    @Json(name = "abnormal_id")
    var abnormalId: String? = null

    /*  异常 */
    @Json(name = "abnormal_describe")
    var abnormalDescribe: String? = null

    /*  异常照片/视频 */
    @Json(name = "abnormal_oss")
    var abnormalOss: RealmList<AbnormalOssData> = realmListOf()

    /*  隐患故障 */
    @Json(name = "abnormal_level")
    var abnormalLevel: Int? = 1 // 1隐患 2故障

    @Json(name = "abnormal_type")
    var abnormalType: RealmList<SelectItem>? = realmListOf()
}

//抄表检查
class MeterReadingData : RealmObject {
    /*  检查项目 */
    @Json(name = "check_item")
    var checkItem: String? = null

    /*  检查单位 */
    @Json(name = "check_unit")
    var checkUnit: String? = null

    /*  抄表值 */
    @Json(name = "meter_value")
    var meterValue: Float? = null

    /*  阈值 */
    @Json(name = "threshold_value")
    var thresholdValue: Float? = null

    /* 上下限 1：上限 2：下限 */
    @Json(name = "bound")
    var bound: Int? = null

    /*  是否异常 */
    @Json(name = "is_abnormal")
    var isAbnormal: Boolean? = false

    /*  异常id */
    @Json(name = "abnormal_id")
    var abnormalId: String? = null

    /*  异常 */
    @Json(name = "abnormal_describe")
    var abnormalDescribe: String? = null
}

class AbnormalOssData : RealmObject {
    var dataType: Int = AttachmentType.UNKNOWN.code

    @Json(name = "type")
    var type: AttachmentType?
        get() {
            return AttachmentType.fromInt(dataType)
        }
        set(value) {
            dataType = value?.code ?: AttachmentType.UNKNOWN.code
        }

    @Json(name = "url")
    var url: String = ""

    @Json(name = "local_url")
    var localUrl: String = ""

    //视频第一帧，只有视频才有这个属性
    @Json(name = "first_frame")
    var firstFrame: String = ""
}